<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

$this->useClass("Handler_Community");
class Action_Community_RssModerate extends Handler_Community {
  private $pages_wing = 3;
  
  public function process() {
		$aa = $this->aa;
		$acl_data = $aa->getInfo();
		if (!$aa->is_granted('community_edit')) return;

		// -- old theme HACK : 2008-05-21 : lucky -- {{{
		$community_skin = 'platonica';
		$tpl = $this->ctx->tpl;
		$community_model = $this->ctx->mm->getModel("Community");
		$community_model->setDefaultSkin($community_skin);
		$tpl->setSkin($community_skin);
		$views_php = $tpl->findFile('', 'views', $tpl->_skin, 'php');
		unset ($config);
		include $views_php; // got $config
		$this->ctx->rh->views->setViewConfig($config);
		// -- old theme HACK : 2008-05-21 : lucky -- }}}
    
    $view = $this->rh->views->findByName('rss_moderate');
    $view->data = $aa->template_data;
    
    $model = $this->ctx->mm->getModel("Moderate", "m");
    
    if ( isset($this->params['lpage']) && !empty($this->params['lpage']) ) {
      $model->setLPage((integer) abs($this->params['lpage']+0));
    }
    if ( isset($this->params['show_all']) && !empty($this->params['show_all']) ) {
      $model->setDisablePages();
      $view->data['show_all'] = true;
    }  
    $view->data['moderate_list'] = $model->getModerateItems($view->data['community']['oid']);

    $pages = $model->getPages();
    if ( $pages > 1 ) {
      $lpage = $model->getLPage();
      if ( $lpage > 1 ) {
        $min = $lpage - $this->pages_wing;
        if ( $min < 1 ) {
          $min = 1;
        }
      } else {
        $min = 1;
      }
      
      $max = $lpage + $this->pages_wing;
      if ( $max > $pages ) {
        $max = $pages;
      }

      $pager = array();
      for ( $i=$min; $i<=$max; $i++ ) {
        $pager[] = array( 'lpage'=>$i );
        if ( $i == $lpage ) {
          $pager[count($pager)-1]['current'] = true;
        }
      }
      
      if ( $max < $pages ) {
        $view->data['max_page'] = $pages;
      }
      if ( $min > 1 ) {
        $view->data['min_page'] = 1;
      }
      
      $view->data['pager'] = $pager;
      $view->data['lpage'] = $lpage;
    }    
    //print '<pre style="text-align:left;">'; print_r($view->data);exit;
    
    $view->data['moderate_tab'] = true;
  
    $this->rh->response->setContent($view);
  }
}